package com.black.pay.service.impl;

import com.black.pay.dao.UserMapper;
import com.black.pay.model.User;
import com.black.pay.model.UserExample;
import com.black.pay.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    public User get(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

    public void save(User user) {
        userMapper.insert(user);
    }

    public User selectOne(UserExample example) {
        List<User> users =userMapper.selectByExample(example);
        if (users == null || users.size() == 0) {
            return null;
        }
        return users.get(0);
    }

    public List<User> list(UserExample example) {
        return userMapper.selectByExample(example);
    }
}
